<template>
  <div>
    <el-form :inline="true">
      <el-form-item label="库位编码">
        <el-input v-model="binL.binL_Code" placeholder="请输入库位编码" />
      </el-form-item>

      <el-form-item label="库位数量">
        <el-input v-model="binL.binL_Nums" placeholder="请输入库位数量" />
      </el-form-item>

      <el-form-item label="当前状态" style="width: 20%">
  <el-select v-model="binL.binL_Status" placeholder="请选择当前状态" clearable>
    <el-option label="空闲" value="0" />
    <el-option label="锁定" value="1" />
  </el-select>
</el-form-item>
      <el-button type="primary" @click="getTableData">查询</el-button>
    </el-form>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" width="50" />
      <el-table-column prop="binL_Code" label="库位编码" width="120" />

      <el-table-column prop="binL_Type" label="库位类型" width="120">
        <template v-slot="scope">
          <el-text>{{ getBinLType(scope.row.binL_Type) }}</el-text>
        </template>
      </el-table-column>

      <el-table-column prop="binL_UserType" label="库位使用方式" width="120" />
      <el-table-column prop="binL_GoodsCode" label="商品编码" width="120" />
      <el-table-column prop="binL_Width" label="库位宽度" width="120" />
      <el-table-column prop="binL_Height" label="库位高度" width="120" />
      <el-table-column prop="binL_Length" label="库位长度" width="120" />
      <el-table-column prop="binL_Volume" label="库位体积" width="120" />
      <el-table-column prop="binL_Nums" label="库位数量" width="120" />
      <el-table-column prop="binL_UseNums" label="库位已用数量" width="120" />
      <el-table-column prop="binL_Weight" label="库位总重量" width="120" />
      <el-table-column prop="binL_MinNums" label="库位下限容量" width="120" />

      <el-table-column prop="binL_Status" label="库位状态" width="120">
        <template v-slot="scope">
          <el-tag :type="getBinLStatusType(scope.row.binL_Status)">
            {{ getBinLStatus(scope.row.binL_Status) }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column prop="binL_Description" label="库位描述" width="120" />
      <el-table-column prop="address" label="操作" />
    </el-table>
    <el-pagination v-model:current-page="binL.pageIndex" v-model:page-size="binL.pageSize" :page-sizes="[1, 5, 10, 30]"
      :background="true" layout="total, sizes, prev, pager, next, jumper" :total="binL.totalCount"
      @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
</template>

<script lang="ts" setup>
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { ElMessage } from 'element-plus';





const tableData = ref([]);
const binL = reactive({
  binL_Code: '',
  binL_Nums: '',
  binL_Status: '',
  binL_UserType: null,
  totalCount: 0,
  totalPage: 0,
  pageIndex: 1,
  pageSize: 10,
});

const getTableData = () => {
  axios.get('http://localhost:5115/api/BinLocation/GetBinLocation', {
    params: {
      binL_Code: binL.binL_Code,
      binL_Nums: binL.binL_Nums,
      binL_Status: binL.binL_Status,
      binL_UserType: binL.binL_UserType,
      pageIndex: binL.pageIndex,
      pageSize: binL.pageSize,
    },
  })
    .then((res) => {
      tableData.value = res.data.data.data;
      binL.totalCount = res.data.data.totalCount;
      binL.totalPage = res.data.data.totalPage;
    })
    .catch((error) => {
      console.error('获取库位数据失败:', error);
      ElMessage.error('获取库位数据失败，请稍后重试');
    });
};

const getBinLType = (type: number) => type === 0 ? '库位' : '货架';

const getBinLStatus = (status: number) => status === 0 ? '空闲' : '锁定';

const getBinLStatusType = (status: number) => status === 0 ? 'success' : 'warning';

onMounted(() => {
  getTableData();
});
const handleSizeChange = (val: number) => {
  binL.pageSize = val
  getTableData()

}
const handleCurrentChange = (val: number) => {
  binL.pageIndex = val
  getTableData()
}

</script>
